import 'package:flutter/material.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MyAppFull();
  }
}

class MyAppFull extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return MyAppState();
  }
}

class MyAppState extends State<MyAppFull> {
  var _pageList = [
    new FirstPage(),
    new SecondPage(),
    new ThirdPage(),
  ];
  var _pageTitle = const [
    "首页",
    "发现",
    "引导",
  ];
  final _pageIcon = [
    Icons.home,
    Icons.email,
    Icons.pages,
  ];
  @override
  void initState() {
    super.initState();
    print("initState");
  }

  @override
  void deactivate() {
    print("deactivate");
    super.deactivate();
  }

  @override
  void dispose() {
    super.dispose();
    print("dispose");
  }

  Text _getTabTitle(int curIndex) {
    if (curIndex == _pageIndex) {
      return new Text(_pageTitle[curIndex],
          style: new TextStyle(fontSize: 16.0, color: const Color(0xff1296db)));
    } else {
      return new Text(_pageTitle[curIndex],
          style: new TextStyle(fontSize: 16.0, color: const Color(0xff515151)));
    }
  }

  Icon _getTabIcon(int curIndex) {
    if (curIndex == _pageIndex) {
      return Icon(_pageIcon[curIndex], color: Color(0xff1296db));
    } else {
      return Icon(_pageIcon[curIndex], color: Color(0xff515151));
    }
  }

  var _pageIndex = 0;
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      title: "底部导航",
      theme: ThemeData.light(),
      home: Scaffold(
        body: _pageList[_pageIndex],
        bottomNavigationBar: BottomNavigationBar(
          backgroundColor: Color(0x33ff0000),
          items: [
            BottomNavigationBarItem(
                icon: _getTabIcon(0), title: _getTabTitle(0)),
            BottomNavigationBarItem(
                icon: _getTabIcon(1), title: _getTabTitle(1)),
            BottomNavigationBarItem(
                icon: _getTabIcon(2), title: _getTabTitle(2)),
          ],
          onTap: _onBarTap,
        ),
      ),
    );
  }

  void _onBarTap(int value) {
    print("_onBarTap $value");
    setState(() => _pageIndex = value);
  }
}

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: Text("1"),
      appBar: AppBar(
        title: Text("1"),
      ),
    );
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: Text("2"),
      appBar: AppBar(
        title: Text("2"),
      ),
    );
  }
}

class ThirdPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: Text("3"),
      appBar: AppBar(
        title: Text("3"),
      ),
    );
  }
}
